package com.zhiyizhen.handheld.component.pharmacy.view;

import android.content.Context;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.zhiyizhen.handheld.R;
import com.zhiyizhen.handheld.component.pharmacy.bean.GroupDetailListBean;

/**
 * description
 */
public class GiveShuyeUnitLayout extends LinearLayout {

    private TextView seqTv;
    private TextView drugInfoTv;
    private TextView thisTimeCountTv;
    private TextView totalCountTv;
    private TextView remarkTv;
    private TextView hasGiveTv;
    private TextView usageCountTv;


    public GiveShuyeUnitLayout(Context context, int seq, GroupDetailListBean detailListBean) {
        super(context);
        initView(context);
        String drugInfo = getStringBuilder(detailListBean).toString();
        String usage = detailListBean.getDosage() + detailListBean.getDosageUnitText();
        String remark = detailListBean.getRemark();
        String totalCount = detailListBean.getTotalOutQty() + detailListBean.getTotalOutQtyUnitText();
        String hasGive = detailListBean.getDeliveryQty() + detailListBean.getTotalOutQtyUnitText();
        String thisTimeCount = detailListBean.getCurrentDeliveryQty() + detailListBean.getTotalOutQtyUnitText();
        setData(seq, drugInfo, usage, remark, totalCount, hasGive, thisTimeCount);
    }

    @NonNull
    private static StringBuilder getStringBuilder(GroupDetailListBean detailListBean) {
        StringBuilder drugInfoSb = new StringBuilder();
        drugInfoSb.append(detailListBean.getDrugName());
        drugInfoSb.append(" ");
        if(detailListBean.getDrugDosage() != null) {
            drugInfoSb.append(detailListBean.getDrugDosage())
                    .append(detailListBean.getDrugDosageUnitText())
                    .append("*");
        }
        drugInfoSb.append(detailListBean.getMinPackQty());
        drugInfoSb.append(detailListBean.getMinPackUnitText());
        drugInfoSb.append("/")
                .append(detailListBean.getPackUnitText());
        return drugInfoSb;
    }

    public GiveShuyeUnitLayout(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    private void initView(Context context) {
        inflate(context, R.layout.view_give_shuye_seq, this);
        setOrientation(LinearLayout.HORIZONTAL);
        seqTv = findViewById(R.id.seqTv);
        usageCountTv = findViewById(R.id.usageCountTv);
        drugInfoTv = findViewById(R.id.drugInfoTv);
        hasGiveTv = findViewById(R.id.hasGiveTv);
        thisTimeCountTv = findViewById(R.id.thisTimeCountTv);
        totalCountTv = findViewById(R.id.totalCountTv);
        remarkTv = findViewById(R.id.remarkTv);
    }

    private void setData(int seq, String drugInfo, String usage, String remark, String totalCount, String hasGive, String thisTimeCount) {
        seqTv.setText(String.valueOf(seq));
        drugInfoTv.setText(drugInfo);
        usageCountTv.setText(usage);
        thisTimeCountTv.setText(thisTimeCount);
        totalCountTv.setText(totalCount);
        remarkTv.setText(remark);
        hasGiveTv.setText(hasGive);
    }


}